refactor: replace dict-based config with type-safe vendor classes#4
Merged
Conversation
Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
⚙️ Control Options:
|
Co-Authored-By: blank@buildwithfern.com <blank@buildwithfern.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor: replace dict-based config with type-safe vendor classes
Summary
Replaces the old shorthand-string and dict-based vendor configuration (
Agent(llm="openai/gpt-4")) with type-safe Pydantic vendor classes. This is a breaking API change — the previousAgentOptionsTypedDict and all shorthand parsing functions are removed.New API pattern:
What's new:
vendors/package with base classes (BaseLLM,BaseTTS,BaseSTT,BaseMLLM,BaseAvatar) and concrete implementations for ~30 vendorsBaseModelvalidation withextra = "forbid"on all vendor option classesLiteraltype aliases for vendor-specific sample rates (e.g.,ElevenLabsSampleRate,CartesiaSampleRate)with_avatar()time and session startWhat's removed:
AgentOptionsTypedDict_parse_llm_shorthand(),_parse_tts_shorthand(),_parse_stt_shorthand()avatar_types.py(validation logic moved intoAgentandAgentSession)Updates since last revision
src/agoraio/__init__.py:AgentOptions,is_heygen_avatar,is_akool_avatar,validate_avatar_config,validate_tts_sample_ratewere still referenced in the top-level__init__.pybut no longer exist in the wrapper module. This was causing the mypy CI check to fail.Review & Testing Checklist for Human
to_config()methods produce dicts with keys like"vendor","params","api_key", etc. These must exactly match what the generated Agora SDK types expect. Test with a real API call to ensure no field name mismatches — CI only checks types, not runtime correctness..with_avatar(HeyGenAvatar(...))(requires 24kHz) and.with_tts(ElevenLabsTTS(..., sample_rate=16000))(wrong rate). Verify it raisesValueErroratwith_avatar()time. Also test the reverse order (TTS after avatar) to ensureAgentSession._validate_avatar_config()catches it.OpenAI(api_key="", model=123)orElevenLabsTTS(key="", model_id="", voice_id="", sample_rate=99999)). Confirm Pydantic raisesValidationErrorwith helpful messages.OpenAI(shows autocomplete forapi_key,model, etc. with type hints.Notes
to_config()output, and avatar/TTS validation logic.OpenAITTS.sample_rateproperty always returns24000(hardcoded) since OpenAI TTS only supports 24kHz output.extra = "forbid"to catch typos in keyword arguments.Link to Devin run: https://app.devin.ai/sessions/756e000c856649af9c8655b0ef4e1038
Requested by: @fern-support